from django import template

register = template.Library()
    

## 
## Verbose Name
## 
## This filter will return the object's verbose name, either as defined in the
## object's "Meta" subclass or by Django itself.
## 

@register.filter
def verboseName(object):
    return object._meta.verbose_name
    

## 
## Verbose Name Plural
## 
## This filter will return the object's plural verbose name, either as defined in the
## object's "Meta" subclass or by Django itself.
## 

@register.filter
def verboseNamePlural(object):
    return object._meta.verbose_name_plural
    

## 
## Class Name
## 
## This filter will return the object's class name using Python's built-in constants.
## 

@register.filter
def className(obj, arg=None):

    # Queryset object
    try:
        if hasattr(obj.model, '__name__'):
            return obj.model.__name__
    except AttributeError, e:
        pass
    
    # Form object
    try:
        if hasattr(obj.Meta.model, '__name__'):
            return obj.Meta.model.__name__
    except AttributeError, e:
        pass
    
    # Any object
    try:
        if hasattr(obj.__class__, '__name__'):
            return obj.__class__.__name__
    except AttributeError, e:
        pass
    